package com.jl.jlapp.mvp.activity;

import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.jl.jlapp.R;
import com.jl.jlapp.eneity.ImageBean;
import com.jl.jlapp.eneity.ImgUploadModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.utils.MimeTypeUtils;
import com.jl.jlapp.utils.Tools;
import com.jl.jlapp.utils.loader.Loader;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionNo;
import com.yanzhenjie.permission.PermissionYes;
import com.yanzhenjie.permission.Rationale;
import com.yanzhenjie.permission.RationaleListener;
import com.yanzhenjie.permission.Request;
import com.yzs.imageshowpickerview.ImageShowPickerBean;
import com.yzs.imageshowpickerview.ImageShowPickerListener;
import com.yzs.imageshowpickerview.ImageShowPickerView;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.PicassoEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import org.reactivestreams.Subscription;

import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody.Part;
import okhttp3.RequestBody;

public class AddVatInvoicePicActivity
        extends AppCompatActivity {
    private static final int REQUEST_CODE_CHOOSE = 233;
    String bankAccountStr;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    String depositBankStr;
    int id = 0;
    int isUpdate = 0;
    List<ImageBean> list;
    MultipartBody.Part[] partList = new MultipartBody.Part[10];
    List<String> picUrlList = new ArrayList();
    @BindView(R.id.it_picker_view)
    ImageShowPickerView pickerView;
    private ProgressDialog progressDialog;
    private RationaleListener rationaleListener = new RationaleListener() {
        public void showRequestPermissionRationale(int paramAnonymousInt, Rationale paramAnonymousRationale) {
            paramAnonymousRationale.resume();
        }
    };
    List<String> realPicUrlList = new ArrayList();
    String registeredAddressStr;
    String registeredTelStr;
    @BindView(R.id.return_btn)
    ImageView returnBtn;
    String taxpayerIdentificationNumberStr;
    @BindView(R.id.title)
    TextView title;
    String unitNameStr;
    int userId = 0;

    @PermissionNo(300)
    private void getPermissionNo(List<String> paramList) {
        Toast.makeText(this, "未授权", Toast.LENGTH_SHORT).show();
    }

    @PermissionYes(300)
    private void getPermissionYes(List<String> paramList) {
    }

    private void photo(List<String> paramList) {
        this.partList = new MultipartBody.Part[10];
        int i = 0;
        while (i < paramList.size()) {
            File localObject = new File((String) paramList.get(i));
            if (localObject != null) {
                RequestBody localRequestBody = RequestBody.create(MediaType.parse(MimeTypeUtils.getMimeType((File) localObject)), (File) localObject);
                Part file = Part.createFormData("file", ((File) localObject).getName(), localRequestBody);
                this.partList[i] = file;
            }
            i += 1;
        }
    }

    public void buildProgressDialog() {
        if (this.progressDialog == null) {
            this.progressDialog = new ProgressDialog(this);
            this.progressDialog.setProgressStyle(0);
        }
        this.progressDialog.setMessage("加载中");
        this.progressDialog.setCancelable(true);
        this.progressDialog.show();
    }

    public void cancelProgressDialog() {
        if ((this.progressDialog != null) && (this.progressDialog.isShowing())) {
            this.progressDialog.dismiss();
        }
    }

    public String getRealFilePath(Context paramContext, Uri paramUri) {
        if (paramUri == null) {
            return null;
        }

//    String str = paramUri.getScheme();
//    Object localObject2 = null;
//    Object localObject3 = null;
//    String localObject1 = paramUri.getPath();
//    for (;;)
//    {
//      this.realPicUrlList.add(localObject1);
//      return (String)localObject1;
//      if ("file".equals(str))
//      {
//        localObject1 = paramUri.getPath();
//      }
//      else
//      {
//        localObject1 = localObject3;
//        if ("content".equals(str))
//        {
//          str = paramUri.getAuthority();
//          if (str.equals("media"))
//          {
//            paramContext = paramContext.getContentResolver().query(paramUri, new String[] { "_data" }, null, null, null);
//            localObject1 = localObject3;
//            if (paramContext != null)
//            {
//              localObject1 = localObject2;
//              if (paramContext.moveToFirst())
//              {
//                int i = paramContext.getColumnIndex("_data");
//                localObject1 = localObject2;
//                if (i > -1) {
//                  localObject1 = paramContext.getString(i);
//                }
//              }
//              paramContext.close();
//            }
//          }
//          else
//          {
//            localObject1 = localObject3;
//            if (str.equals("com.jl.jlapp.publish.MyFileProvider")) {
//              localObject1 = Environment.getExternalStorageDirectory() + "/Pictures/" + paramUri.getLastPathSegment();
//            }
//          }
//        }
//      }
//    }

        return "";
    }

    public void handleImgPicker() {
        this.list = new ArrayList();
        this.pickerView.setImageLoaderInterface(new Loader());
        this.pickerView.setNewData(this.list);
        this.pickerView.setShowAnim(true);
        this.pickerView.setMaxNum(1);
        this.pickerView.setOneLineShowNum(5);
        this.pickerView.setmDelLabel(2131165417);
        this.pickerView.setmAddLabel(2131165621);
        this.pickerView.setmPicSize(200);
        this.pickerView.setPickerListener(new ImageShowPickerListener() {
            public void addOnClickListener(int paramAnonymousInt) {
                if ((ActivityCompat.checkSelfPermission(AddVatInvoicePicActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0) || (ActivityCompat.checkSelfPermission(AddVatInvoicePicActivity.this, "android.permission.READ_EXTERNAL_STORAGE") != 0)) {
                    AndPermission.with(AddVatInvoicePicActivity.this).requestCode(300).permission(new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"}).rationale(AddVatInvoicePicActivity.this.rationaleListener).callback(this).start();
                    return;
                }
                Matisse.from(AddVatInvoicePicActivity.this).choose(MimeType.of(MimeType.JPEG, new MimeType[]{MimeType.PNG})).countable(true).maxSelectable(paramAnonymousInt + 1).capture(true).captureStrategy(new CaptureStrategy(true, "com.jl.jlapp.publish.MyFileProvider")).restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED).gridExpectedSize(300).thumbnailScale(0.85F).imageEngine(new PicassoEngine()).theme(R.style.Matisse_Dracula).forResult(233);
            }

            public void delOnClickListener(int paramAnonymousInt1, int paramAnonymousInt2) {
                AddVatInvoicePicActivity.this.realPicUrlList.remove(paramAnonymousInt1);
            }

            public void picOnClickListener(List<ImageShowPickerBean> paramAnonymousList, int paramAnonymousInt1, int paramAnonymousInt2) {
                Intent intent = new Intent(AddVatInvoicePicActivity.this, PhotoViewActivity.class);
                intent.putExtra("picUrl", (String) AddVatInvoicePicActivity.this.realPicUrlList.get(paramAnonymousInt1));
                intent.putExtra("flag", 1);
                AddVatInvoicePicActivity.this.startActivity(intent);
            }
        });
        this.pickerView.show();
        AndPermission.with(this).requestCode(300).permission(new String[]{"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.CAMERA"}).rationale(this.rationaleListener).callback(this).start();
        this.pickerView.getDataList();
    }

    public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent) {
        super.onActivityResult(paramInt1, paramInt2, paramIntent);
        if ((paramInt1 == 233) && (paramInt2 == -1)) {
            List<Uri> uris = Matisse.obtainResult(paramIntent);
            if (uris.size() == 1) {
                this.pickerView.addData(new ImageBean(getRealFilePath(this, (Uri) uris.get(0))));
            } else {
                ArrayList arrayList = new ArrayList();
                Iterator<Uri> iterator = uris.iterator();
                while (iterator.hasNext()) {
                    arrayList.add(new ImageBean(getRealFilePath(this, iterator.next())));
                }
                this.pickerView.addData(arrayList);

            }
        }
    }

    protected void onCreate(@Nullable Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_add_vat_invoice_pic);
        ButterKnife.bind(this);
        Tools.addActivity(this);
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        Intent intent = getIntent();
        this.isUpdate = intent.getIntExtra("isUpdate", 0);
        if (this.isUpdate == 1) {
            this.id = intent.getIntExtra("id", 0);
            this.title.setText("修改增票资质");
        }
        this.unitNameStr = intent.getStringExtra("unitName");
        this.taxpayerIdentificationNumberStr = intent.getStringExtra("taxpayerIdentificationNumber");
        this.registeredAddressStr = intent.getStringExtra("registeredAddress");
        this.registeredTelStr = intent.getStringExtra("registeredTel");
        this.depositBankStr = intent.getStringExtra("depositBank");
        this.bankAccountStr = intent.getStringExtra("bankAccount");
        handleImgPicker();
        this.returnBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                AddVatInvoicePicActivity.this.finish();
            }
        });
        this.btnSubmit.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                AddVatInvoicePicActivity.this.submitData();
            }
        });
    }

    public void submitData() {
        if (this.realPicUrlList.size() > 0) {
            buildProgressDialog();
            photo(this.realPicUrlList);
            this.btnSubmit.setClickable(false);
            this.btnSubmit.setTextColor(getResources().getColor(R.color.font_grey));
            this.btnSubmit.setBackgroundResource(R.drawable.btn_gray_large);
            Net.get().uploadPhoto(this.partList).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<ImgUploadModel>() {

                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(ImgUploadModel imgUploadModel) {

                }

                @Override
                public void onError(Throwable t) {
                    Toast.makeText(AddVatInvoicePicActivity.this, "请上传资质文件", Toast.LENGTH_SHORT).show();

                }

                @Override
                public void onComplete() {

                }
            });
        }
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/AddVatInvoicePicActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */